package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BusCout;
import com.ruoyi.system.service.IBusCoutService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 合伙人收益Controller
 *
 * @author ruoyi
 * @date 2024-01-03
 */
@Controller
@RequestMapping("/system/cout")
public class BusCoutController extends BaseController
{
    private String prefix = "system/cout";

    @Autowired
    private IBusCoutService busCoutService;

    @RequiresPermissions("system:cout:view")
    @GetMapping()
    public String cout()
    {
        return prefix + "/cout";
    }

    /**
     * 查询合伙人收益列表
     */
    @RequiresPermissions("system:cout:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusCout busCout)
    {
        startPage();
        List<BusCout> list = busCoutService.selectBusCoutList(busCout);
        return getDataTable(list);
    }

    /**
     * 导出合伙人收益列表
     */
    @RequiresPermissions("system:cout:export")
    @Log(title = "合伙人收益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusCout busCout)
    {
        List<BusCout> list = busCoutService.selectBusCoutList(busCout);
        ExcelUtil<BusCout> util = new ExcelUtil<BusCout>(BusCout.class);
        return util.exportExcel(list, "合伙人收益数据");
    }

    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<BusCout> util = new ExcelUtil<BusCout>(BusCout.class);
        List<BusCout> busCoutList = util.importExcel(file.getInputStream());
        String message = busCoutService.importBusCout(busCoutList, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<BusCout> util = new ExcelUtil<BusCout>(BusCout.class);
        return util.importTemplateExcel("合伙人收益表数据");
    }

    /**
     * 新增合伙人收益
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合伙人收益
     */
    @RequiresPermissions("system:cout:add")
    @Log(title = "合伙人收益", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusCout busCout)
    {
        return toAjax(busCoutService.insertBusCout(busCout));
    }

    /**
     * 修改合伙人收益
     */
    @RequiresPermissions("system:cout:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BusCout busCout = busCoutService.selectBusCoutById(id);
        mmap.put("busCout", busCout);
        return prefix + "/edit";
    }

    /**
     * 修改保存合伙人收益
     */
    @RequiresPermissions("system:cout:edit")
    @Log(title = "合伙人收益", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusCout busCout)
    {
        return toAjax(busCoutService.updateBusCout(busCout));
    }

    /**
     * 删除合伙人收益
     */
    @RequiresPermissions("system:cout:remove")
    @Log(title = "合伙人收益", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busCoutService.deleteBusCoutByIds(ids));
    }

}
